package com.foreveross.fetl.listener;

import javax.servlet.ServletContextEvent;

import org.apache.log4j.Logger;

import com.dayatang.spring.webapp.DayatangContextLoaderListener;
import com.foreveross.fetl.common.InstanceFactory;
import com.foreveross.fetl.common.cfg.ConfigContainer;
import com.foreveross.fetl.common.cfg.system.DefaultPropertiesLoader;
import com.foreveross.fetl.common.db.hbase.HBasePropertiesLoader;

public class AppStartupListener extends DayatangContextLoaderListener {

	private static final Logger log = Logger
			.getLogger(AppStartupListener.class);

	public void contextDestroyed(ServletContextEvent arg0) {
		log.info("destroy config file......");
		ConfigContainer.getInstance().destroy();
		super.contextDestroyed(arg0);
	}

	public void contextInitialized(ServletContextEvent arg0) {
		//一个spring上下文初始化
		InstanceFactory.setServletContext(arg0.getServletContext());
		// 加载配置文件
		log.info("init config file......");
		// 系统默认的config.properties配置文件
		ConfigContainer.getInstance().register(DefaultPropertiesLoader.class);
		// hbase数据库配置文件(可以改为像jdbc.properties文件一样由spring加载)
		ConfigContainer.getInstance().register(HBasePropertiesLoader.class);
		//代理IP使用到的配置信息
//		ConfigContainer.getInstance().register(ProxyIpPropertiesLoader.class);
		
		//必须先加载这个，才能加载后面的初始化代理ＩＰ池
		log.info("init dayatang/spring context......");
		super.contextInitialized(arg0);
	}

}
